home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / MPMain.c < prev    next >
C/C++ Source or Header  |  2000-09-17  |  22KB  |  696 lines

  1. #define NO_LOCKPUBSCREENLIST
  2.  
  3. #include "MP.h"
  4. #include <clib/extras/exec_protos.h>
  5. #include <clib/alib_protos.h>
  6. #include <extras/libs.h>
  7.  
  8. #include <utility/hooks.h>
  9. #include <intuition/sghooks.h>
  10. #include "patchdata.h"
  11.  
  12. #include <proto/locale.h>
  13. #include <debug.h>
  14.  
  15. #include <extras/macros/exec.h>
  16.  
  17. long __stack = 4096;
  18.  
  19. LONG InPatch=0;
  20.  
  21. UBYTE EnvFile[]   ="ENV:ModePro.pref",
  22.       EnvArcFile[]="ENVARC:ModePro.pref";
  23.        
  24. extern UBYTE   Version[];
  25. extern UBYTE   ModePro[];
  26. extern LONG SemVersion,
  27.             SemRevision;
  28. extern struct List BackdropList;
  29.  
  30. extern struct SignalSemaphore LockPubSem;
  31.  
  32. #define NO_WIN_PATCH
  33.  
  34.  
  35. BYTE PublicSignal;
  36. struct Process *MPTask;
  37.  
  38. struct Screen ASM *(*OldOpenScreen)(REG __a0 struct NewScreen *,
  39.                                     REG __a6 struct IntuitionBase *);
  40. struct Screen ASM *(*OldOpenScreenTagList)(REG __a0 struct ExtNewScreen *ns,
  41.                                            REG __a1 struct TagItem *taglist,
  42.                                            REG __a6 struct IntuitionBase * );
  43. LONG ASM (*OldCloseScreen)(REG __a0 struct Screen *,
  44.                            REG __a6 struct IntuitionBase *);
  45. struct Window ASM *(*OldOpenWindow)(REG __a0 struct NewWindow *nw,
  46.                                     REG __a6 struct IntuitionBase *lib);
  47. struct Window ASM *(*OldOpenWindowTagList)(REG __a0 struct NewWindow *nw,
  48.                                            REG __a1 struct TagItem *tags,
  49.                                            REG __a6 struct IntuitionBase *lib);
  50. BOOL ASM *(*OldLayoutMenusA)(REG __a0 struct Menu *fm,
  51.                              REG __a1 APTR vi, 
  52.                              REG __a2 struct TagItem *tags,
  53.                              REG __a6 struct Library *lib);
  54.  
  55. LONG ASM *(*OldCloseWorkBench)(REG __a6 struct IntuitionBase *lib);
  56.  
  57. struct Screen * __asm (*OldLockPubScreen)(register __a0 UBYTE *Name,
  58.                                           register __a6 struct Library *);
  59. void __asm (*OldUnlockPubScreen)(register __a0 UBYTE *Name,
  60.                                  register __a1 struct Screeen *,
  61.                                  register __a6 struct Library *);
  62.  
  63.  
  64.  
  65. struct List * __asm (*OldLockPubScreenList)(register __a6 struct Library *);
  66. void __asm (*OldUnlockPubScreenList)(register __a6 struct Library *);
  67.  
  68.  
  69.  
  70. BOOL    V39;
  71. ULONG   Deinstall=FALSE;
  72.                 
  73. struct NewBroker NewBroker=
  74. {
  75.   NB_VERSION,
  76.   "ModePro",
  77.   ModePro,
  78.   0,
  79.   NBU_UNIQUE | NBU_NOTIFY,
  80.   COF_SHOW_HIDE,
  81.   0,0,0
  82. };
  83.  
  84.  
  85.  
  86. UWORD NumDriPens;
  87.  
  88. /*
  89. UWORD defaultpens[]=
  90. {
  91.   0,1,1,2,1,3,1,0,2,1,2,1
  92. };
  93. */
  94.  
  95. //void asm _PROLOG(register __a0 const char *where);
  96. //void asm _EPILOG(register __a0 const char *where);
  97.  
  98. //#define _EPILOG _MYEPILOG
  99. //#define _PROLOG _MYPROLOG
  100.  
  101. struct TextAttr Topaz8 = { "topaz.font",8,0,0};
  102.  
  103. struct MsgPort *BrokerPort,
  104.                *CatchPort,
  105.                *ReplyPort;
  106. struct Message *ms;
  107.  
  108. #include <proto/cybergraphics.h>
  109.  
  110. struct IntuitionBase *IntuitionBase; 
  111. struct GfxBase       *GfxBase;
  112. struct LocaleBase    *LocaleBase;
  113. struct Library       *AslBase,
  114.                      *CxBase,
  115.                      *CyberGfxBase,
  116.                      *DiskfontBase,
  117.                      //*GadToolsBase,
  118.                      *IconBase,
  119.                      *IFFParseBase,
  120.                      *LayersBase,
  121.                      *UtilityBase,
  122.                      *DataTypesBase;
  123.  
  124. struct Libs MP_Libs[]=
  125. {
  126.   (APTR *)&AslBase,      "asl.library",         38,0,
  127.   (APTR *)&CxBase,       "commodities.library", 36,0,
  128.   (APTR *)&CyberGfxBase, "cybergraphics.library",39,OLF_OPTIONAL, 
  129.   (APTR *)&DataTypesBase,"datatypes.library"  ,39,OLF_OPTIONAL,
  130.   (APTR *)&DiskfontBase, "diskfont.library",   36,0,
  131. //  (APTR *)&GadToolsBase, "gadtools.library",   36,0,
  132.   (APTR *)&GfxBase,      "graphics.library",   36,0,
  133.   (APTR *)&IconBase,     "icon.library",       36,0,
  134.   (APTR *)&IFFParseBase, "iffparse.library",   36,0,
  135.   (APTR *)&IntuitionBase,"intuition.library",  36,0,
  136.   (APTR *)&LayersBase,   "layers.library",     36,0,
  137.   (APTR *)&UtilityBase,  "utility.library",    36,0,
  138.   0,0,0
  139. };
  140.  
  141. CxObj   *Broker;
  142. CxMsg   *cxmsg;
  143. ULONG   cxsig;
  144. ULONG   sigrcvd;
  145.  
  146. /*** Tooltypes ***/
  147.  
  148. UBYTE *Hotkey="lamiga p",
  149.       Popup=TRUE;
  150. BYTE  Priority=0;
  151. //UBYTE *UserFontName=0;
  152. //LONG   UserFontSize=8;
  153. STRPTR PrefsPath;
  154.  
  155. struct Catalog *Catalog;
  156.  
  157. struct MPSem *MPSem;
  158.  
  159. void main(int argc, char **argv) 
  160. {
  161.   ULONG l;
  162.  
  163. /*
  164.   DataTypesBase=OpenLibrary("datatypes.library",39);
  165. */
  166.   if(LocaleBase=(struct LocaleBase *)OpenLibrary("locale.library",38))
  167.     Catalog=OpenCatalog(NULL,(STRPTR)"modepro.catalog", TAG_DONE);
  168.   else
  169.     Catalog=NULL;
  170.   
  171.   InitStrings();
  172.  
  173.   if(ex_OpenLibs(argc,//                                                                               (4.63.2) (09/17/00)
  174.               "ModePro",
  175.               GetString(MSG_REQ_COULDNT_OPEN_LIBS),
  176.               GetString(MSG_REQ_NAME_VER_FMT),
  177.               GetString(MSG_REQ_OK),
  178.               MP_Libs))
  179.   {
  180.     if(MPSem=AllocVec(sizeof(struct MPSem),MEMF_PUBLIC|MEMF_CLEAR))
  181.     {
  182.       NewList(&MPSem->ForcedEditPort.mp_MsgList);
  183.       NewList(&BackdropList);
  184.       MPSem->ForcedEditPort.mp_Flags=PA_IGNORE;
  185.       
  186.       NewBroker.nb_Descr=GetString(MSG_COMMODITY_TITLE);
  187.   
  188.       if(((struct Library *)IntuitionBase)->lib_Version>38)
  189.       {
  190.         NumDriPens=12;
  191.         V39=TRUE;
  192.       }
  193.       else
  194.       {
  195.         NumDriPens=9;
  196.         V39=FALSE;
  197.       }
  198.       if(GetArgs(argc,argv))
  199.       {
  200.         {
  201.           struct SignalSemaphore *sem;
  202.         
  203.           sem=&MPSem->SharedSem;
  204.           for(l=0;l<SEMAPHORES;l++)
  205.             InitSemaphore(&sem[l]);
  206.         }
  207.         
  208.         InitSemaphore(&LockPubSem);
  209.   
  210.         MPSem->SharedSem.ss_Link.ln_Name =(UBYTE *)"ModePro";
  211.         MPSem->SharedSem.ss_Link.ln_Pri  =0;
  212.         MPSem->Enabled =TRUE;
  213.         MPSem->Version =SemVersion;
  214.         MPSem->Revision=SemRevision;
  215.         MPSem->HotKey  =Hotkey;
  216.         MPSem->FirstPrefsOpen=1;
  217. /*  
  218.         if(ps=LockPubScreen(NULL))
  219.         {
  220.           di=GetScreenDrawInfo(ps);
  221.           for(l=0;l<di->dri_NumPens && l<NumDriPens;l++)
  222.             defaultpens[l]=di->dri_Pens[l];      
  223.           FreeScreenDrawInfo(ps,di);
  224.           UnlockPubScreen(NULL,ps);
  225.         }
  226. */  
  227.         if(BrokerPort=CreateMsgPort())
  228.         { 
  229.           NewBroker.nb_Pri=Priority;
  230.           NewBroker.nb_Port=BrokerPort;
  231.           if(Broker=CxBroker(&NewBroker,NULL))
  232.           {
  233.             AddHotKey(Broker,BrokerPort,Hotkey,EVT_HOTKEY);
  234.             if(CatchPort=CreateMsgPort())
  235.             {
  236.               if(MPSem->DaemonPort=CreateMsgPort())
  237.               {
  238.                 if(ReplyPort=CreateMsgPort())
  239.                 {
  240.                   if((PublicSignal=AllocSignal(-1))>=0)
  241.                   {
  242.                     MPTask=(struct Process *)FindTask(0);
  243.                     cxsig=1L<<BrokerPort->mp_SigBit;
  244.                     ActivateCxObj(Broker,1);
  245.           
  246.                     NewList(&MPSem->OpenList);
  247.                     for(l=0;l<NUM_LISTS;l++)
  248.                       NewList(&MPSem->PromotionList[l]);
  249.                     
  250.                     if(!DaemonLoadFile(EnvFile))
  251.                         DaemonLoadFile(EnvArcFile);
  252.                         
  253.                     LoadPalettePrefs();
  254. //#include <pragmas/intuition_pragmas.h>
  255.                     Forbid();
  256.                     OldCloseScreen        =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x42) ,(FUNCCAST)NewCloseScreen);
  257.                     OldOpenScreenTagList  =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x264),(FUNCCAST)NewOpenScreenTagList);
  258.                     OldOpenScreen         =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0xc6) ,(FUNCCAST)NewOpenScreen);
  259.                     OldLockPubScreen      =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x1fe),(FUNCCAST)NewLockPubScreen);
  260.                     OldUnlockPubScreen    =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-516,    (FUNCCAST)NewUnlockPubScreen);
  261.  
  262. #ifndef NO_LOCKPUBSCREENLIST
  263.                     OldLockPubScreenList  =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x20a),(FUNCCAST)NewLockPubScreenList);
  264.                     OldUnlockPubScreenList=(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x210),(FUNCCAST)NewUnlockPubScreenList);
  265. #endif
  266.                     OldCloseWorkBench     =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x4e) ,(FUNCCAST)NewCloseWorkBench);
  267.                     OldLayoutMenusA       =(FUNCCAST)SetFunction((struct Library *)GadToolsBase ,-(0x42) ,(FUNCCAST)NewLayoutMenusA);
  268.                     OldOpenWindowTagList  =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x25e),(FUNCCAST)NewOpenWindowTagList);
  269.                     OldOpenWindow         =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0xcc) ,(FUNCCAST)NewOpenWindow);
  270.                     
  271.                     Permit();
  272.                  
  273.                     AddSemaphore((struct SignalSemaphore *)MPSem);
  274.                     ProcessInput();
  275.                     RemSemaphore((struct SignalSemaphore *)MPSem);
  276.                     
  277.                     ObtainSemaphore(&MPSem->ListSem);
  278.                     ReleaseSemaphore(&MPSem->ListSem);
  279.                     ObtainSemaphore(&MPSem->PrefsSem);
  280.                     ReleaseSemaphore(&MPSem->PrefsSem);
  281.   
  282.                     ProcessMPMessages();
  283.   
  284.                     {
  285.                       struct MPMessage *mpm;
  286.                       while(mpm=(struct MPMessage *)GetMsg(ReplyPort))
  287.                         FreeVec(mpm);
  288.                     }
  289.   
  290.                     FreeAllDefLists(MPSem->PromotionList);
  291.                     FreeSignal(PublicSignal);
  292.                   }
  293.                   DeleteMsgPort(ReplyPort);
  294.                 }
  295.                 DeleteMsgPort(MPSem->DaemonPort);
  296.               }
  297.               DeleteMsgPort(CatchPort);
  298.             }
  299.             DeleteCxObjAll(Broker);
  300.             while(cxmsg=(CxMsg *)GetMsg(BrokerPort))
  301.               ReplyMsg((struct Message *)cxmsg);
  302.           }/* endif CxBroker() */
  303.           DeleteMsgPort(BrokerPort);
  304.         }// endif CreateMsgPort(BrokerPort)
  305.         // ArgArrayDone();
  306.         CleanupArgs(argc);
  307.       }// endif GetArgs() 
  308.       FreeVec(MPSem);
  309.     }
  310.     ex_CloseLibs(MP_Libs);//                                                                           (4.63.1) (09/17/00)
  311.   } 
  312.   if(LocaleBase)
  313.   {
  314.     CloseCatalog(Catalog);
  315.     CloseLibrary((struct Library *)LocaleBase);
  316.   }
  317. }
  318.   
  319. void ProcessInput(void)
  320. {
  321.  
  322.   struct DefaultNode *catdnode;
  323.   ULONG  replysig,portsig,catchsig,signal,msgtype,pubsig,allsigs,daemonsig;
  324.   LONG msgid;
  325.  
  326.   
  327.   daemonsig = 1 << MPSem->DaemonPort->mp_SigBit;
  328.   catchsig  = 1 << CatchPort->mp_SigBit;
  329.   portsig   = 1 << BrokerPort->mp_SigBit;
  330.   pubsig    = 1 << PublicSignal; 
  331.   replysig  = 1 << ReplyPort->mp_SigBit;
  332.  
  333.   allsigs=daemonsig | replysig | pubsig | catchsig | portsig | SIGBREAKF_CTRL_C;
  334.  
  335.   if(Popup)
  336.     ShowGUI();
  337.  
  338.   while (!Deinstall)
  339.   {
  340.     signal=Wait (allsigs);
  341.  
  342.     if(SIGBREAKF_CTRL_C & signal)
  343.       CheckToQuit();
  344.  
  345.     if(daemonsig & signal)
  346.       ProcessMPMessages();
  347.  
  348.     if(replysig & signal)
  349.     {
  350.       struct MPMessage *mpm;
  351.       
  352.       while(mpm=(struct MPMessage *)GetMsg(ReplyPort))
  353.         FreeVec(mpm);
  354.     }
  355.  
  356.     if(pubsig & signal)
  357.     {
  358.       SetSignal(0,pubsig);
  359.       ClosePubScreens();
  360.     }
  361.     
  362.     if(catchsig & signal)
  363.     {
  364.       while(catdnode=(struct DefaultNode *)GetMsg(CatchPort))
  365.       {
  366.         AddDNode(catdnode->Type,catdnode);
  367.       }
  368. //      if(MPSem->CatchPopup)
  369. //      ShowGUI();
  370.     }
  371.         
  372.     if(portsig & signal)
  373.     {
  374.       while(cxmsg=(CxMsg *)GetMsg(BrokerPort))
  375.       {
  376.         msgid=CxMsgID(cxmsg);
  377.         msgtype=CxMsgType(cxmsg);
  378.         ReplyMsg((struct Message *)cxmsg);     
  379.         switch(msgtype)
  380.         {
  381.           case CXM_IEVENT:
  382.             switch(msgid)
  383.             {
  384.               case EVT_HOTKEY:
  385.                 ShowGUI();
  386.                 break;
  387.               default:
  388.                 {
  389.                   struct OpenNode *on;
  390.                   // This was ListSem... why?
  391.                   ObtainSemaphoreShared(&MPSem->OpenListSem);
  392.                   on=(struct OpenNode *)MPSem->OpenList.lh_Head;
  393.                   while(on->on_Node.ln_Succ)
  394.                   {
  395.                     if(on=(struct OpenNode *)msgid)
  396.                     {
  397.                       ScreenToFront(on->Screen);
  398.                       ActivateWindow(on->Screen->FirstWindow);
  399.                       RemoveCxObj(on->Cx);
  400.                       AttachCxObj(Broker,on->Cx);
  401.                       /*
  402.                       
  403.                       DeleteCxObjAll(on->Cx);
  404.                       
  405.                       on->Cx=AddHotKey(Broker,BrokerPort,on->HotKey,(ULONG)on);
  406.                       */
  407.                       break;
  408.                     }
  409.                     on=(struct OpenNode *)on->on_Node.ln_Succ;
  410.                   }
  411.                   ReleaseSemaphore(&MPSem->OpenListSem);
  412.                 }
  413.             }
  414.             break;
  415.           case CXM_COMMAND:
  416.             switch(msgid)
  417.             {
  418.               case CXCMD_DISABLE:
  419.                 MPSem->Enabled=FALSE;
  420.                 ActivateCxObj(Broker,0);
  421.                 SendPrefsMsg(MP_REFRESH,0,0);
  422.                 break;
  423.               case CXCMD_ENABLE:
  424.                 MPSem->Enabled=TRUE;
  425.                 ActivateCxObj(Broker,1);
  426.                 SendPrefsMsg(MP_REFRESH,0,0);
  427.                 break;
  428.               case CXCMD_KILL:
  429.                 CheckToQuit();
  430.                 break;
  431.               case CXCMD_UNIQUE:
  432.               case CXCMD_APPEAR:
  433.                 ShowGUI();
  434.                 break;
  435.               case CXCMD_DISAPPEAR:
  436.                 HideGUI();
  437.                 break;
  438.             }
  439.             break;        
  440.         }
  441.       }
  442.     }
  443.   }
  444.   HideGUI();
  445. }    
  446.  
  447. void ProcessMPMessages(void)
  448. {
  449.   struct MPMessage *mpm;
  450.  
  451.   while(mpm=(struct MPMessage *)GetMsg(MPSem->DaemonPort))
  452.   {
  453. DEBUG_CODE(DKP("DaemonMsg ReplyPort %8lx Command %ld  Code %ld  Data %8lx\n",((struct Message *)mpm)->mn_ReplyPort, mpm->Command,mpm->Code,mpm->Data););
  454.     
  455.     switch(mpm->Command)
  456.     {
  457.       case MP_QUIT:
  458.         CheckToQuit();
  459.         break;
  460.  
  461.       case MP_SHOWGUI:
  462.         mpm->Code=ShowGUI();
  463.         break;
  464.  
  465.       case MP_SCREENOPENED:
  466.         {
  467.           struct OpenNode *on;
  468.           
  469.           on=(struct OpenNode *)mpm->Data;
  470.           ReplyMsg((struct Message *)mpm);
  471.           mpm=0;
  472.           
  473.           AddBackdrop(on->Screen,on->DN);
  474.         }
  475.         break;
  476.         
  477.       case MP_SCREENCLOSING:
  478.         {
  479.           struct OpenNode *on;
  480.         
  481.           on=(struct OpenNode *)mpm->Data;
  482.           RemoveBackdrop(on->Screen);
  483.         }
  484.         break;
  485.  
  486.       case MP_PUBSCREEN:
  487.         {
  488.           
  489.         }
  490.         break;
  491.  
  492.         /*
  493.       case MP_NEWNODE:
  494.  
  495.         AddDNode(mpm->Code,mpm->Data);
  496.         break;
  497.       case MP_REMNODE:
  498.         RemDNode(mpm->Data);
  499.         break;
  500.         */      
  501.     }
  502.     if(mpm)
  503.       ReplyMsg((struct Message *)mpm);
  504.   }
  505. }
  506.  
  507.  
  508.  
  509. void CheckToQuit(void)
  510. {
  511.   APTR  CheckCloseScreen,
  512.         CheckOpenScreen,
  513.         CheckOpenScreenTagList,
  514.         CheckOpenWindow,
  515.         CheckOpenWindowTagList,
  516.         CheckCloseWorkBench,
  517.         CheckLayoutMenusA,
  518.         CheckLockPubScreen,
  519.         CheckUnlockPubScreen;
  520. #ifndef NO_LOCKPUBSCREENLIST
  521.   APTR  CheckLockPubScreenList,
  522.         CheckUnlockPubScreenList;
  523. #endif
  524.   BOOL patchedover=FALSE,
  525.        screensopen=FALSE;
  526.   ULONG len;
  527.   UBYTE *warning=0;
  528.   UBYTE *warn;
  529.   
  530.   ObtainSemaphoreShared(&MPSem->ListSem);
  531.   ObtainSemaphore(&MPSem->OpenListSem);
  532.   Forbid();
  533.   
  534.   if(!Deinstall && !InPatch)
  535.   {
  536.     
  537.     if(IsListEmpty(&MPSem->OpenList))
  538.     {
  539.       /**** check LVOs and make sure their mine ****/
  540.       /**** get LVOs,so put mine in thier, and get the result ****/ 
  541.       CheckCloseScreen        =SetFunction((struct Library *)IntuitionBase,-(0x42), (FUNCCAST)OldCloseScreen);
  542.       CheckOpenScreenTagList  =SetFunction((struct Library *)IntuitionBase,-(0x264),(FUNCCAST)OldOpenScreenTagList);
  543.       CheckOpenScreen         =SetFunction((struct Library *)IntuitionBase,-(0xc6), (FUNCCAST)OldOpenScreen);
  544.       CheckCloseWorkBench     =SetFunction((struct Library *)IntuitionBase,-(0x4e) ,(FUNCCAST)OldCloseWorkBench);
  545.       CheckLockPubScreen      =SetFunction((struct Library *)IntuitionBase,-(0x1fe),(FUNCCAST)OldLockPubScreen);
  546.       CheckUnlockPubScreen    =SetFunction((struct Library *)IntuitionBase,-516,    (FUNCCAST)OldUnlockPubScreen);
  547. #ifndef NO_LOCKPUBSCREENLIST
  548.       CheckLockPubScreenList  =SetFunction((struct Library *)IntuitionBase,-(0x20a),(FUNCCAST)OldLockPubScreenList);
  549.       CheckUnlockPubScreenList=SetFunction((struct Library *)IntuitionBase,-(0x210),(FUNCCAST)OldUnlockPubScreenList);
  550. #endif
  551.       CheckLayoutMenusA       =SetFunction((struct Library *)GadToolsBase ,-(0x42), (FUNCCAST)OldLayoutMenusA);
  552.       CheckOpenWindowTagList  =SetFunction((struct Library *)IntuitionBase,-(0x25e),(FUNCCAST)OldOpenWindowTagList);
  553.       CheckOpenWindow         =SetFunction((struct Library *)IntuitionBase,-(0xcc), (FUNCCAST)OldOpenWindow);
  554.       /**** now restore the LVOs to whatever they were ***/
  555.      
  556.       if((APTR)CheckCloseScreen         != (APTR)NewCloseScreen         ||
  557.          (APTR)CheckOpenScreenTagList   != (APTR)NewOpenScreenTagList   ||
  558.          (APTR)CheckOpenScreen          != (APTR)NewOpenScreen          || 
  559.          (APTR)CheckCloseWorkBench      != (APTR)NewCloseWorkBench      ||
  560.          (APTR)CheckLockPubScreen       != (APTR)NewLockPubScreen       ||
  561.          (APTR)CheckUnlockPubScreen     != (APTR)NewUnlockPubScreen     ||
  562. #ifndef NO_LOCKPUBSCREENLIST
  563.          (APTR)CheckLockPubScreenList   != (APTR)NewLockPubScreenList   ||
  564.          (APTR)CheckUnlockPubScreenList != (APTR)NewUnlockPubScreenList ||
  565. #endif
  566.          (APTR)CheckLayoutMenusA        != (APTR)NewLayoutMenusA        ||
  567.          (APTR)CheckOpenWindowTagList   != (APTR)NewOpenWindowTagList   ||
  568.          (APTR)CheckOpenWindow          != (APTR)NewOpenWindow)
  569.  
  570.       {                 
  571.         SetFunction((struct Library *)IntuitionBase,-(0x42), (FUNCCAST)CheckCloseScreen);
  572.         SetFunction((struct Library *)IntuitionBase,-(0x264),(FUNCCAST)CheckOpenScreenTagList);
  573.         SetFunction((struct Library *)IntuitionBase,-(0xc6) ,(FUNCCAST)CheckOpenScreen);
  574.         SetFunction((struct Library *)IntuitionBase,-(0x4e) ,(FUNCCAST)CheckCloseWorkBench);  
  575.         SetFunction((struct Library *)IntuitionBase,-(0x1fe),(FUNCCAST)CheckLockPubScreen);
  576.         SetFunction((struct Library *)IntuitionBase,-516,    (FUNCCAST)CheckUnlockPubScreen);
  577.         
  578. #ifndef NO_LOCKPUBSCREENLIST
  579.         SetFunction((struct Library *)IntuitionBase,-(0x20a),(FUNCCAST)CheckLockPubScreenList);
  580.         SetFunction((struct Library *)IntuitionBase,-(0x210),(FUNCCAST)CheckUnlockPubScreenList);
  581. #endif
  582.  
  583.         SetFunction((struct Library *)GadToolsBase ,-(0x42) ,(FUNCCAST)CheckLayoutMenusA);
  584.         SetFunction((struct Library *)IntuitionBase,-(0x25e),(FUNCCAST)CheckOpenWindowTagList);
  585.         SetFunction((struct Library *)IntuitionBase,-(0xcc) ,(FUNCCAST)CheckOpenWindow);
  586.         
  587.         patchedover=TRUE;
  588.       }
  589.       else
  590.       {
  591.         Deinstall=TRUE;
  592.         SendPrefsMsg(MP_QUIT,0,0);
  593.       }
  594.     }
  595.     else
  596.     {
  597.       struct OpenNode *on;
  598.     
  599.       warn=GetString(MSG_REQ_CANT_QUIT_SCREENS);
  600.       
  601.       len=strlen(warn);
  602.       
  603.       on=(struct OpenNode *)MPSem->OpenList.lh_Head;
  604.       while(on->on_Node.ln_Succ)
  605.       {
  606.         len+=strlen(on->Screen->Title)+4;
  607.         on=(struct OpenNode *)on->on_Node.ln_Succ;
  608.       }
  609.       if(warning=AllocVec(len,MEMF_PUBLIC|MEMF_CLEAR|MEMF_NO_EXPUNGE))    
  610.       {
  611.         strcpy(warning,warn);
  612.         on=(struct OpenNode *)MPSem->OpenList.lh_Head;
  613.         while(on->on_Node.ln_Succ)
  614.         {
  615.           strcat(warning,"\n  ");
  616.           strcat(warning,on->Screen->Title);
  617.           on=(struct OpenNode *)on->on_Node.ln_Succ;
  618.         }
  619.         screensopen=TRUE;
  620.       }
  621.     }
  622.     ReleaseSemaphore(&MPSem->OpenListSem);
  623.     ReleaseSemaphore(&MPSem->ListSem);
  624.     
  625.     Permit();
  626.     
  627.     if(patchedover)
  628.       EZReq(0,0,ModePro,GetString(MSG_REQ_CANT_QUIT_PATCHED_OVER),GetString(MSG_REQ_OK),0);   
  629.     
  630.     if(screensopen && warning)
  631.     {
  632.       EZReq(0,0,ModePro,warning,GetString(MSG_REQ_OK),0);
  633.       FreeVec(warning);
  634.     }
  635.   }
  636. }
  637.  
  638. LONG SendPrefsMsg(ULONG Command, ULONG Code, APTR Data)
  639. {
  640.   LONG rv=-1;
  641.   struct MPMessage *mpm,*rm;
  642.   struct MsgPort *mp;
  643.  
  644.   ObtainSemaphore(&MPSem->PortSem);
  645.   if(MPSem->PrefsPort)
  646.   {
  647.     if(mp=CreateMsgPort())
  648.     {
  649.       rv=0;
  650.       if(mpm=AllocVec(sizeof(struct MPMessage),MEMF_PUBLIC|MEMF_CLEAR))
  651.       {
  652.         mpm->Command=Command;
  653.         mpm->Code=Code;
  654.         mpm->Data=Data;
  655.         mpm->mp_Message.mn_ReplyPort=mp;
  656.         PutMsg(MPSem->PrefsPort,(struct Message *)mpm);
  657.          rm=0;
  658.         
  659.         ReleaseSemaphore(&MPSem->PortSem);              
  660.         while(rm!=mpm)
  661.         {
  662.           WaitPort(mp);
  663.           rm=(struct MPMessage *)GetMsg(mp);
  664.         }
  665.         ObtainSemaphore(&MPSem->PortSem);
  666.         
  667.         rv=1; 
  668.       }
  669.       DeleteMsgPort(mp);
  670.     }
  671.   } 
  672.   ReleaseSemaphore(&MPSem->PortSem);
  673.   return(rv);
  674. }
  675.  
  676. BOOL DaemonLoadFile(STRPTR FileName)
  677. {
  678.   //LONG error;
  679.   BOOL rv;
  680.  
  681.   // no need for protection, the lists are not public
  682.   // when this function is called.  
  683.   rv=LoadFile(MPSem->PromotionList,FileName);
  684.   /*
  685.   if(error=IoErr())
  686.   {
  687.     UBYTE errstr[91];
  688.  
  689.     Fault(error,GetString(MSG_REQ_LOAD_ERROR),errstr,90);
  690.     EZReq(0,0,ModePro,errstr,GetString(MSG_REQ_OK),0);
  691.   }
  692.   */
  693.   return(rv);
  694. }    
  695.  
  696.